package com.jzr.board.controller.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jzr.board.db1.dto.VitalSignDto;
import com.jzr.board.db1.model.TPatient;
import com.jzr.board.db1.model.TVitalSign;
import com.jzr.board.db1.service.TVitalSignService;
import com.jzr.board.db1.vo.PatientBaseVo;
import com.jzr.common.entity.vo.Result;
import com.jzr.common.util.U;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/vitalSign")
public class VitalSignController {
    @Autowired
    TVitalSignService vitalSignService;
    @GetMapping("/getVitalSign")
    public Result<Map<String,Object>> getVitalSign(TPatient record){
        if(U.isBlank(record.getCode()) && U.isBlank(record.getCureNo())){
            return Result.fail("提供参数code,cureNo");
        }
        List<PatientBaseVo> patientBaseVos = vitalSignService.getPatentList(record);
        VitalSignDto vitalSignDto = new VitalSignDto();
        vitalSignDto.setPatientCode(record.getCode());
        vitalSignDto.setPatientCureNo(record.getCureNo());

        List<TVitalSign> vitalSigns = vitalSignService.getVitalSignList(vitalSignDto);
        Map<String,Object> res = new HashMap<>();
        res.put("pat",patientBaseVos ==null || patientBaseVos.isEmpty() ? null : patientBaseVos.get(0));
        res.put("vitalSigns",vitalSigns);
        return Result.success("成功",res);
    }

    @GetMapping("/getPatientList")
    public Result<List<PatientBaseVo>> getPatientList(TPatient record){
        if(U.isBlank(record) || (U.isBlank(record.getDeptCode()) && U.isBlank(record.getCode()) && U.isBlank(record.getCureNo()))){
            return Result.fail("请提供参数");
        }
        List<PatientBaseVo> list = vitalSignService.getPatentList(record);
        return Result.success("成功",list);
    }
    @PostMapping("/getVitalSignList")
    public Result<List<TVitalSign>> getVitalSignList(VitalSignDto record){
        List<TVitalSign> list = vitalSignService.getVitalSignList(record);
        return Result.success("成功",list);
    }
    @GetMapping("/getOpDateList")
    public Result<List<Object>> getOpDateList(VitalSignDto record){
        QueryWrapper<TVitalSign> qw = new QueryWrapper<>();
        qw.select("DISTINCT op_date");
        qw.orderByAsc("op_date");
        List<Object> list = vitalSignService.listObjs(qw);
        return Result.success("成功",list);
    }

}
